package bb.lanxing.activity.mine

import android.app.Activity
import android.app.AlertDialog
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.Environment
import android.text.TextUtils
import android.view.View
import android.widget.LinearLayout
import android.widget.Switch
import android.widget.TextView
import android.widget.Toast
import androidx.lifecycle.lifecycleScope
import bb.lanxing.App
import bb.lanxing.BuildConfig
import bb.lanxing.R
import bb.lanxing.activity.DeviceSettingsActivity
import bb.lanxing.activity.base.BaseActivity
import bb.lanxing.activity.base.WebActivity
import bb.lanxing.chat.utils.IntentUtils
import bb.lanxing.common.config.Constants.FOLDER_CRASH
import bb.lanxing.common.config.Constants.FOLDER_LOGGER
import bb.lanxing.lib.devices.core.utils.SyncSharedPreference
import bb.lanxing.manager.RemoteSharedPreference
import bb.lanxing.manager.SPConstant
import bb.lanxing.manager.ShareDialogMgr
import bb.lanxing.manager.SharedManager
import bb.lanxing.network.BiCiCallback
import bb.lanxing.network.MyHttpClient
import bb.lanxing.network.NetSubscribe
import bb.lanxing.util.AppFileUtils
import bb.lanxing.util.Log
import bb.lanxing.util.PostMan
import bb.lanxing.util.PostMan.ShareFile
import bb.lanxing.util.RxPermissionUtil
import bb.lanxing.util.RxPermissionUtil.PermissionCallBack
import bb.lanxing.util.ShareLogUtil
import bb.lanxing.util.debug.TransLogger
import bb.lanxing.util.upgrade.LxUpgradeStrategyRequestCallback
import bb.lanxing.view.BiciAlertDialogBuilder
import com.blankj.utilcode.util.CacheDiskStaticUtils
import com.blankj.utilcode.util.DeviceUtils
import com.blankj.utilcode.util.FileUtils
import com.blankj.utilcode.util.ToastUtils
import com.tencent.connect.UserInfo
import com.tencent.connect.common.Constants
import com.tencent.tauth.IUiListener
import com.tencent.tauth.Tencent
import com.tencent.tauth.UiError
import com.tencent.upgrade.core.UpgradeManager
import com.umeng.analytics.MobclickAgent
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.json.JSONException
import org.json.JSONObject
import rx.Observable
import rx.Observer
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
import java.io.File
import java.io.IOException

class NewMoreActivity : BaseActivity() {
  private lateinit var autoFront: Switch
  private lateinit var autoUpload: Switch
  private lateinit var llFitManager: LinearLayout
  private lateinit var mCrashHandlerView: View
  private lateinit var mFeedbackView: View
  private lateinit var mHelpView: View
  private lateinit var mLlContainer: View
  private lateinit var mRecommend: View

  private lateinit var mExitAccount: View
  private val mShareDialogMgr: ShareDialogMgr? = null
  private lateinit var mShareView: View
  private lateinit var mSosMsg: View
  private lateinit var mTaobaoView: View
  private lateinit var mTvPrivacyAgreement: View
  private lateinit var mTvUserAgreement: View
  private lateinit var mVersionContainer: View
  private lateinit var mCheckUpdatesContainer: View
  private lateinit var personalizedPush: Switch
  private lateinit var swSync: Switch
  private lateinit var syncQQhealth: Switch
  private lateinit var transLogSwitch: Switch
  private lateinit var txtExportSyncLog: TextView
  private lateinit var txtExportTransLog: TextView
  private lateinit var txtImportTtsLog: TextView
  private lateinit var useHttpsSwitch: Switch

  private lateinit var showExperimental: Switch
  private lateinit var txtClearStorage: TextView
  private lateinit var mDeviceSettignsContainer: View

  private lateinit var versionFlag: TextView
  private lateinit var versionView: TextView
  private val mIsSharing = false
  val mHints: LongArray = LongArray(4)

  override fun onCreate(bundle: Bundle?) {
    super.onCreate(bundle)
    setContentView(R.layout.activity_new_more)
    bindView(window.decorView)
    setupActionBar(true)
    versionView.text = App.getContext().versionName
    if (SharedManager.getInstance().versionClick < App.getContext().versionCode) {
      versionFlag.visibility = View.VISIBLE
    } else {
      versionFlag.visibility = View.GONE
    }
    if (SharedManager.getInstance().autoUploadMode == 2) {
      autoUpload.isChecked = false
    } else {
      autoUpload.isChecked = true
    }
    autoUpload.setOnCheckedChangeListener { _, z: Boolean ->
      if (z) {
        SharedManager.getInstance().autoUploadMode = 1
      } else {
        SharedManager.getInstance().autoUploadMode = 2
      }
    }
    useHttpsSwitch.isChecked = SharedManager.getInstance().isUseHttps
    useHttpsSwitch.setOnCheckedChangeListener { _, z: Boolean ->
      SharedManager.getInstance().isUseHttps = z
    }

    showExperimental.isChecked = SharedManager.getInstance().isShowExperimental
    showExperimental.setOnCheckedChangeListener { _, z: Boolean ->
      SharedManager.getInstance().isShowExperimental = z
    }


    transLogSwitch.isChecked = SharedManager.getInstance().isTransLog
    transLogSwitch.setOnCheckedChangeListener { _, z: Boolean ->
      SharedManager.getInstance().setTransLog(z)
    }
    personalizedPush.isChecked = SharedManager.getInstance().isEnablePersonalizedPush
    personalizedPush.setOnCheckedChangeListener { _, z: Boolean ->
      SharedManager.getInstance().setPersonalizedPush(z)
    }
    syncQQhealth.isChecked = SharedManager.getInstance().isSyncQQHealth
    syncQQhealth.setOnCheckedChangeListener { _, z: Boolean ->
      if (z) {
        if (App.getContext().isUserSignin) {
          if (TextUtils.isEmpty(App.getContext().signinUser.qq)) {
            syncQQhealth.isChecked = false
            this@NewMoreActivity.showQQLoginDialog()
            return@setOnCheckedChangeListener
          }
          SharedManager.getInstance().isSyncQQHealth = true
          return@setOnCheckedChangeListener
        }
        App.getContext().userSignin()
        syncQQhealth.isChecked = false
        return@setOnCheckedChangeListener
      }
      SharedManager.getInstance().isSyncQQHealth = false
    }
    autoFront.isChecked = RemoteSharedPreference.getInstance().getBoolean(SPConstant.KEY_APP_AUTO_FRONT, true)
    autoFront.setOnCheckedChangeListener { _, z ->
      RemoteSharedPreference.getInstance().setValue(SPConstant.KEY_APP_AUTO_FRONT, z)
    }
    swSync.isChecked = RemoteSharedPreference.getInstance().getBoolean(SPConstant.KEY_SYNC_SERVICE_FOREGROUND, true)
    swSync.setOnCheckedChangeListener { _, z ->
      RemoteSharedPreference.getInstance().setValue(SPConstant.KEY_SYNC_SERVICE_FOREGROUND, z)
      SyncSharedPreference.saveSyncMode(this@NewMoreActivity, z)
    }
    txtImportTtsLog.setOnClickListener {
      uploadLog(FOLDER_CRASH, TYPE_CRASH)
    }
    txtExportTransLog.setOnClickListener {
      if (SharedManager.getInstance().isTransLog) {
        val file = File(TransLogger.getInstance().logPath)
        if (file.exists() && file.length() > 0) {
          showShareDialog(file);
          return@setOnClickListener
        } else {
          ToastUtils.showShort(R.string.st_no_log)
          return@setOnClickListener
        }
      }
      Toast.makeText(this@NewMoreActivity, "未开启蓝牙传输日志记录", Toast.LENGTH_LONG).show()
    }
    txtExportSyncLog.setOnClickListener {
      uploadLog(FOLDER_LOGGER, TYPE_LOG)
    }
    mDeviceSettignsContainer = findViewById(R.id.deviceSettignsContainer)
    mDeviceSettignsContainer.setOnClickListener(this::onDeviceSettingsClick)
    val tvFeedback = findViewById<TextView>(R.id.tv_feedback)
    tvFeedback.setOnClickListener {
      WebActivity.start(
        activity, getString(R.string.mine_setting_more_feedback), bb.lanxing.common.config.Constants.URL_SETTING_FEEDBACK
      )
    }
  }

  private fun uploadLog(folderName: String, type: String) {
    if (App.getContext().isUserSignin()) {
      val folder = AppFileUtils.buildExternalDirectoryPath(folderName)
      val file = File(folder)
      if (file.exists()) {
        val fileList = FileUtils.listFilesInDir(file)
        fileList?.let {
          val size = it.size
          if (size > 0) {
            showMyProgressDialog()
          } else {
            ToastUtils.showShort(R.string.st_no_log)
            return
          }
          for ((i, item) in it.withIndex()) {
            Observable.create(
              NetSubscribe(
                MyHttpClient.uploadLog(
                  type, item.absolutePath, "", App.getContext().userPhone
                )
              )
            ).subscribeOn(Schedulers.io()).observeOn(
              AndroidSchedulers.mainThread()
            ).subscribe(object : Observer<String> {
              override fun onCompleted() {
              }

              override fun onError(e: Throwable) {
                App.getContext().showMessage(e.message)
                if (i == size - 1) {
                  dismissLoadingDialog()
                }
              }

              override fun onNext(str: String) {
                FileUtils.delete(item)
                if (i == size - 1) {
                  dismissLoadingDialog()
                  ToastUtils.showShort(R.string.toast_upload_successful)
                }
              }
            })
          }
        }
      }
    } else {
      ToastUtils.showShort(R.string.common_text_unauthorize)
    }
  }

  private fun showShareDialog(file: File?) {
    val strArr = arrayOf("微信", Constants.SOURCE_QQ, "其他")
    val builder = AlertDialog.Builder(this)
    builder.setTitle("请选择分享到哪个平台")
    builder.setItems(strArr) { _, i ->
      when (i) {
        0 -> {
          ShareLogUtil.shareFile(this@NewMoreActivity, file, ShareLogUtil.PACKAGE_NAME_WX)
        }

        1 -> {
          ShareLogUtil.shareFile(this@NewMoreActivity, file, ShareLogUtil.PACKAGE_NAME_QQ)
        }

        else -> {
          PostMan.shareFile(
            this@NewMoreActivity.context, ShareFile().putFile(this@NewMoreActivity.context, file), "Export Fit"
          )
        }
      }
    }
    builder.show()
  }

  private fun showQQLoginDialog() {
    BiciAlertDialogBuilder(this).setTitle("此功能需要绑定QQ账号后才可以使用,是否去绑定？").setPositiveButton("去绑定") { dialogInterface, i ->
      gotoBindQQ(
        this@NewMoreActivity
      )
    }.setNegativeButton("不了") { dialogInterface, i -> }.show()
  }

  private fun taobaoClick() {
    MobclickAgent.onEventValue(this, "more_taobao", null, 1)
    val intent = Intent()
    intent.setAction("android.intent.action.VIEW")
    intent.setData(Uri.parse(bb.lanxing.common.config.Constants.TAOBAO_URL))
    startActivity(intent)
  }

  private fun shareClick() {
    MobclickAgent.onEventValue(this, "more_share", null, 1)
    try {
      startActivity(
        Intent(
          "android.intent.action.VIEW", Uri.parse("market://details?id=bb.lanxing")
        )
      )
    } catch (e: Exception) {
      e.printStackTrace()
      App.getContext().showMessage("请先安装安卓市场。")
    }
  }

  private fun helpClick() {
    MobclickAgent.onEventValue(this, "more_help", null, 1)
    IntentUtils.gotoWebBrowser(this, bb.lanxing.common.config.Constants.HELP_URL, null)
  }

  private fun onClickContainer() {
    val jArr = this.mHints
    System.arraycopy(jArr, 1, jArr, 0, jArr.size - 1)
    val jArr2 = this.mHints
    jArr2[jArr2.size - 1] = System.currentTimeMillis()
    if (System.currentTimeMillis() - mHints[0] <= 1000) {
      llFitManager.visibility = View.VISIBLE
    }
  }

  private fun onFitManager() {
//        startActivity(new Intent(this, FitListActivity.class));
  }

  private fun crashHandlerClick() {
    val url = getManufacturerUrl()
    IntentUtils.gotoWebBrowser(
      activity, url, null
    )
  }

  private fun onUserAgreement() {
    IntentUtils.gotoWebBrowser(
      activity, bb.lanxing.common.config.Constants.URL_USER_AGREEMENT, null
    )
  }

  private fun onPrivacyAgreement() {
    IntentUtils.gotoWebBrowser(
      activity, bb.lanxing.common.config.Constants.URL_PRIVACY_AGREEMENT, null
    )
  }

  private fun versionClick() {
    MobclickAgent.onEventValue(this, "more_version", null, 1)
    IntentUtils.gotoWebBrowser(this, bb.lanxing.common.config.Constants.NEW_VERSION, null)
    SharedManager.getInstance().versionClick = App.getContext().versionCode
    versionFlag.visibility = View.GONE
  }

  private fun checkUpdatesClick() {
    UpgradeManager.getInstance().checkUpgrade(
      true, null, LxUpgradeStrategyRequestCallback()
    )
  }

  private fun onClearStorage() {
    lifecycleScope.launch {
      withContext(Dispatchers.IO) {
        CacheDiskStaticUtils.clear()
      }
      snack(R.string.toast_delete_successful)
    }
  }

  private fun loginByQQ() {
    val createInstance = Tencent.createInstance(bb.lanxing.common.config.Constants.SOCIAL_QQ_APP_ID, this)
    createInstance.login(this, "get_user_info,get_simple_userinfo", object : IUiListener {
      override fun onWarning(i: Int) {
      }

      override fun onComplete(accountObj: Any) {
        UserInfo(this@NewMoreActivity, createInstance.qqToken).getUserInfo(object : IUiListener {
          override fun onWarning(i: Int) {
          }

          override fun onComplete(userInfoObj: Any) {
            this@NewMoreActivity.bindQQ(accountObj.toString(), userInfoObj.toString())
          }

          override fun onError(uiError: UiError) {
            val context = App.getContext()
            context.showMessage("出错: " + uiError.errorMessage + uiError.errorCode + uiError.errorMessage)
          }

          override fun onCancel() {
            App.getContext().showMessage("登录已取消")
          }
        })
      }

      override fun onError(uiError: UiError) {
        val context = App.getContext()
        context.showMessage("出错: " + uiError.errorMessage + uiError.errorCode + uiError.errorMessage)
      }

      override fun onCancel() {
        App.getContext().showMessage("登录已取消")
      }
    })
  }

  fun bindQQ(account: String?, userinfo: String?) {
    showMyProgressDialog("正在绑定QQ...")
    MyHttpClient.userBindThirdParty(object : BiCiCallback(this) {
      @Throws(JSONException::class)
      override fun onResponseString(string: String) {
        try {
          val signinUser = App.getContext().signinUser
          signinUser.qqAuth = account
          signinUser.save()
          App.getContext().showMessage("QQ绑定成功。")
          this@NewMoreActivity.runOnUiThread { syncQQhealth.isChecked = true }
          SharedManager.getInstance().isSyncQQHealth = true
        } catch (e: Exception) {
          e.printStackTrace()
          App.getContext().showMessage("QQ绑定失败。")
        }
      }
    }, account, userinfo)
  }

  private fun sosMsgClick() {
    val intent = Intent()
    intent.setClass(this, SosActivity::class.java)
    startActivity(intent)
  }

  private fun recommendClick() {
    val intent = Intent()
    intent.setClass(this, RecommendActivity::class.java)
    startActivity(intent)
  }

  override fun onResume() {
    super.onResume()
    //TODO:sun
//        if (hasStoragePermission()) {
//            FeedbackAPI.init(getApplication(), bb.lanxing.common.config.Constants.ALI_BAI_CHUAN_FEEDBACK_KEY, bb.lanxing.common.config.Constants.ALI_BAI_CHUAN_FEEDBACK_KEY_SECURE);
//        }
  }

  fun feedBack() {
    MobclickAgent.onEventValue(this, "more_feedback", null, 1)
    val jSONObject = JSONObject()
    try {
      if (App.getContext().isUserSignin) {
        val signinUser = App.getContext().signinUser
        jSONObject.put("userId",  /*EaseConstant.EXTRA_USER_ID*/signinUser.uid)
        jSONObject.put("userName", signinUser.name)
      }
      jSONObject.put("version", BuildConfig.VERSION_NAME)
      jSONObject.put("Android SDK", Build.VERSION.RELEASE)
      jSONObject.put("Device", Build.MANUFACTURER + " " + Build.MODEL)
    } catch (e: JSONException) {
      e.printStackTrace()
    }
    //TODO:sun
//        FeedbackAPI.setAppExtInfo(jSONObject);
//        FeedbackAPI.openFeedbackActivity();
  }

  private fun checkStoragePermission() {
    if (RxPermissionUtil.getInstance().checkPermission(this as BaseActivity, RxPermissionUtil.getStoragePermissions())) {
      uploadDatabase()
    } else {
      showPermissionDialog()
    }
  }

  private fun hasStoragePermission(): Boolean {
    return RxPermissionUtil.getInstance().checkPermission(this as BaseActivity, RxPermissionUtil.getStoragePermissions())
  }

  private fun showPermissionDialog() {
    BiciAlertDialogBuilder(this).setTitle(getString(R.string.permission_request_permission_tips)).setMessage(
      resources.getString(R.string.permission_common_need_storage)
    ).setCancelable(true).setPositiveButton(
      R.string.dialog_btn_ok
    ) { _, _ -> requestStoragePermission() }.show()
  }

  private fun requestStoragePermission() {
    RxPermissionUtil.getInstance().setPermissions(*RxPermissionUtil.getStoragePermissions()).permissionRequestEachCombined(this, object : PermissionCallBack {
      override fun deny() {
      }

      override fun granted() {
        if (!App.isManagersInit) {
          App.getContext().initManagersWithPermissions()
        }
        uploadDatabase()
      }
    })
  }

  private fun bindView(view: View) {
    this.autoUpload = view.findViewById(R.id.autoUpload)
    this.useHttpsSwitch = view.findViewById(R.id.useHttps)
    this.showExperimental = view.findViewById(R.id.show_experimental)
    this.syncQQhealth = view.findViewById(R.id.syncQQhealth)
    this.autoFront = view.findViewById(R.id.autoFront)
    this.swSync = view.findViewById(R.id.sync_service_foreground)
    this.personalizedPush = view.findViewById(R.id.sw_personalized_push)
    this.transLogSwitch = view.findViewById(R.id.switch_trans_log)
    this.llFitManager = view.findViewById(R.id.ll_fit_manager)
    this.versionView = view.findViewById(R.id.versionView)
    this.versionFlag = view.findViewById(R.id.versionFlag)
    this.txtImportTtsLog = view.findViewById(R.id.export_crash_log)
    this.txtExportTransLog = view.findViewById(R.id.export_trans_log)
    this.txtExportSyncLog = view.findViewById(R.id.export_upload_log)
    this.mTaobaoView = view.findViewById(R.id.taobaoView)
    this.mShareView = view.findViewById(R.id.shareView)
    this.mHelpView = view.findViewById(R.id.helpView)
    this.mLlContainer = view.findViewById(R.id.ll_container)
    this.mCrashHandlerView = view.findViewById(R.id.crashHandlerView)
    this.mTvUserAgreement = view.findViewById(R.id.tv_user_agreement)
    this.mTvPrivacyAgreement = view.findViewById(R.id.tv_privacy_agreement)
    this.mVersionContainer = view.findViewById(R.id.versionContainer)
    this.mCheckUpdatesContainer = view.findViewById(R.id.checkUpdatesContainer)
    this.mSosMsg = view.findViewById(R.id.sosMsg)
    this.mRecommend = view.findViewById(R.id.recommend)
    this.mExitAccount = view.findViewById(R.id.exitAccount)
    this.txtClearStorage = view.findViewById(R.id.txt_clear_storage)

    mExitAccount.setVisibility(View.GONE)
    mTaobaoView.setOnClickListener { taobaoClick() }
    mShareView.setOnClickListener { shareClick() }
    mHelpView.setOnClickListener { helpClick() }
    mLlContainer.setOnClickListener { onClickContainer() }
    llFitManager.setOnClickListener { onFitManager() }

    mCrashHandlerView.setOnClickListener { crashHandlerClick() }
    mTvUserAgreement.setOnClickListener { onUserAgreement() }
    mTvPrivacyAgreement.setOnClickListener { onPrivacyAgreement() }
    mVersionContainer.setOnClickListener { versionClick() }
    mCheckUpdatesContainer.setOnClickListener { checkUpdatesClick() }
    mSosMsg.setOnClickListener { sosMsgClick() }
    mRecommend.setOnClickListener { recommendClick() }
    mExitAccount.setOnClickListener {
      val logout = "登出账号"
      toastLong(logout)
      SharedManager.getInstance().isSignoutFlag = false
      finish()
    }
    val databaseView: TextView = view.findViewById(R.id.export_upload_database)
    databaseView.setOnClickListener {
      checkStoragePermission()
    }

    txtClearStorage.setOnClickListener { onClearStorage() }
  }

  private fun uploadDatabase() {
    lifecycleScope.launch {
      showMyProgressDialog()
      val result = withContext(Dispatchers.IO) {
        backupDatabase()
      }
      if (null != result) {
        doUploadDatabase(result)
      } else {
        dismissLoadingDialog()
      }
    }
  }

  private fun doUploadDatabase(path: File) {
    Observable.create(
      NetSubscribe(
        MyHttpClient.uploadLog(
          TYPE_DB, path.absolutePath, "", App.getContext().userPhone
        )
      )
    ).subscribeOn(Schedulers.io()).observeOn(
      AndroidSchedulers.mainThread()
    ).subscribe(object : Observer<String> {
      override fun onCompleted() {
      }

      override fun onError(e: Throwable) {
        App.getContext().showMessage(e.message)
        dismissLoadingDialog()
      }

      override fun onNext(str: String) {
        FileUtils.delete(path)
        dismissLoadingDialog()
        ToastUtils.showShort(R.string.toast_upload_successful)
      }
    })
  }

  private fun backupDatabase(): File? {
    try {
      // 获取应用的数据库路径
      val dbFile: File = context.getDatabasePath("lanxing.db")
      if (dbFile.exists()) {
        // 创建备份目录
        val backupDir = File(Environment.getExternalStorageDirectory(), FOLDER_LOGGER)
        if (!backupDir.exists()) {
          backupDir.mkdirs()
        }

        val backupFile = File(backupDir, "lanxing.db")
        // 复制数据库文件到备份文件
        val ret = FileUtils.copy(dbFile, backupFile)
        if (ret) {
          return backupFile
        }
      }
    } catch (e: IOException) {
      e.printStackTrace()
      Log.e("DatabaseBackupUtil", "数据库备份失败: " + e.message)
    }
    return null
  }

  companion object {
    private const val TYPE_LOG = "APP_LOG"
    private const val TYPE_CRASH = "APP_CRASH"
    private const val TYPE_DB = "APP_DB"
    private const val MANUFACTURER_XIAOMI = "XIAOMI"
    private const val MANUFACTURER_OPPO = "OPPO"
    private const val MANUFACTURER_HUAWEI = "HUAWEI"
    private const val MANUFACTURER_VIVO = "VIVO"
    private const val MANUFACTURER_REALME = "REALME"

    private const val MANUFACTURER_XIAOMI_URL = "https://app.bluebank.com.cn/document/2/"
    private const val MANUFACTURER_OPPO_VIVO_URL = "https://app.bluebank.com.cn/document/4/"
    private const val MANUFACTURER_HUAWEI_URL = "https://app.bluebank.com.cn/document/3/"
    private const val MANUFACTURER_OTHER_URL = "https://app.bluebank.com.cn/document/1/"

    fun gotoBindQQ(activity: Activity) {
      activity.startActivity(Intent(activity, UserInfoActivity::class.java))
    }
  }

  private fun getManufacturerUrl(): String {
    val manufacturer = DeviceUtils.getManufacturer().toUpperCase()
    return when (manufacturer) {
      MANUFACTURER_VIVO, MANUFACTURER_OPPO, MANUFACTURER_REALME -> MANUFACTURER_OPPO_VIVO_URL
      MANUFACTURER_HUAWEI -> MANUFACTURER_HUAWEI_URL
      MANUFACTURER_XIAOMI -> MANUFACTURER_XIAOMI_URL
      else -> {
        MANUFACTURER_OTHER_URL
      }
    }
  }

  fun onDeviceSettingsClick(view: View) {
    if (!App.getContext().isUserSignin()) {
      App.getContext().userSignin()
      return
    }
    startActivity(Intent(this, DeviceSettingsActivity::class.java))
  }
}